﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClickerClimber.Scenes.SplashScreenScene;
using ClickerClimber.Scenes;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace ClickerClimber.Managers
{
    class InputManager
    {
        private static InputManager _instance;

        Vector2 _lastPos;
        Vector2 _pos;
        MouseState _mouseState;
        eState _state;

        public enum eState
        {
            PENDINGTOPROCESS = 0,
            PROCESSED
        };

        public enum eSound
        {
            eSound_Wow = 0
        }

        #region Constructors

        private InputManager()
        {
        }

        /// <summary>
        /// Gets the singleton instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static InputManager Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new InputManager();
                }
                return _instance;
            }
        }

        /// <summary>
        /// Starts up the Singleton
        /// </summary>
        public void StartUp()
        {
            _pos.X = 0;
            _pos.Y = 0;
            _lastPos.X = 0;
            _lastPos.Y = 0;
            _state = eState.PROCESSED;
        }

        /// <summary>
        /// GetPosition
        /// </summary>
        /// <returns></returns>
        public Vector2 GetPosition()
        {
            _pos.X = _mouseState.X;
            _pos.Y = _mouseState.Y;

            return _pos;
        }

        /// <summary>
        /// GetPosition
        /// </summary>
        /// <returns></returns>
        public bool bLeftButtonPressed()
        {
            return (_mouseState.LeftButton == ButtonState.Pressed);
        }

        /// <summary>
        /// GetPosition
        /// </summary>
        /// <returns></returns>
        public void Update()
        {
            _mouseState = Mouse.GetState();
            GameScene gameScene = DataManager.Instance.GameScene;
            if (_mouseState.LeftButton == ButtonState.Pressed)
            {
                if (gameScene != null)
                {
                    if (_state != eState.PENDINGTOPROCESS)
                    {
                        gameScene.OnClick(GetPosition());
                    }
                }
                if (DataManager.Instance.SplashScreenScene != null)
                {
                    DataManager.Instance.SplashScreenScene.OnClick();
                }


                _state = eState.PENDINGTOPROCESS;
            }
            else
            {
                _state = eState.PROCESSED;
            }
        }
        #endregion Constructors

        #region Properties


        public eState State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }

        #endregion Properties
    }
}
